package org.zappee.dannyt.swiz.control
{
	import flash.events.Event;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.ResultEvent;
	
	import org.swizframework.Swiz;
	import org.swizframework.controller.AbstractController;
	import org.zappee.dannyt.swiz.business.Bug;
	import org.zappee.dannyt.swiz.model.ZappeeModel;
	import org.zappee.dannyt.swiz.service.IBugService;

	public class ManageBugController extends AbstractController
	{
		public static const EVENT_SAVE_BUG : String = "saveBugEvent";
		
		[Autowire(bean="zappeeModel")]
		public var model:ZappeeModel;
		
		[Autowire(bean="bugService")]
		public var bugService:IBugService;
		
		public function ManageBugController()
		{
		}
		
		public function saveBug(bug:Bug):void
		{
			var call:AsyncToken = this.bugService.saveBug(bug);
			executeServiceCall(call, onSaveBug);
		}
		
		private function onSaveBug(re:ResultEvent):void
		{
			model.bugs.addItem(re.result);
		}
		
	}
}